package com.atguigu.gulimail.product.demo;

import org.junit.jupiter.api.Test;

import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author fangy
 * @date 2022-08-18 19:09
 */
public class grammar_demo {


    public static void main(String[] args) {


        /**
         List<Employee> emps = Arrays.asList(

         new Employee(101, "张三", 18, 9999.99),
         new Employee(102, "李四", 18, 8888.88),
         new Employee(103, "王五", 18, 7777.77),
         new Employee(104, "赵六", 18, 6666.66)

         );

         Collections.sort(emps,(e1,e2)->{
         if (e1.getAge() == e2.getAge()) {
         return e1.getPrice().compareTo(e2.getPrice());
         } else {
         return Integer.compare(e1.getAge(), e2.getAge());
         }
         });

         for (Employee employee : emps) {
         System.out.println(employee);
         }
         */


//        System.out.println(getStr("  s  e  r  r  t  r  e ", (str) -> str.trim()));
//
//        System.out.println(getStr("  s  e  r  r  t  r  e ", (str) -> str.toUpperCase()));

    }



//	public int getName(int num,MyFunction myFunction) {
//
//		return myFunction.getValue(num);
//
//	}


    @Test
    public void Test01(){

        Employee emp = new Employee();

//        Supplier<String> sup = ()->emp.getName();
        Supplier<String> sup = emp::getName;
        System.out.println(sup.get());

        Supplier<Integer> sup1 = ()->emp.getAge();
//        Supplier<Integer> sup1 = emp::getAge;
        System.out.println(sup1.get());

    }

    @Test
    public void Test02(){

//        Supplier<Employee> sup = ()-> new Employee();
//        System.out.println(sup.get());
//
//        Supplier<Employee> sup2 = Employee::new;
//        Employee employee = sup2.get();
//        System.out.println(employee);

        Function<Integer,Employee> function = Employee::new;
        System.out.println(function);

        Employee employee1 = function.apply(101);
        System.out.println(employee1);

    }


    @Test
    public void Test03(){

        Function<Integer,String[]> function = String[]::new;
        String[] fun = function.apply(23);
        System.out.println(fun.length);

        Function<Integer,String[]> function1 = (x)-> new String[x];
        String[] fun1 = function1.apply(10);
        System.out.println(fun1.length);

    }

    public static String getStr(String str,MyFunction myFunction) {

        return myFunction.getValue(str);

    }

}
